package com.hippo.core.ui.components

import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material3.AlertDialog
import androidx.compose.material3.Button
import androidx.compose.material3.Text
import androidx.compose.material3.TextField
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.unit.dp
import com.hippo.core.R
import com.hippo.core.utils.UiHandler

@Composable
fun InputDialog(onDismiss: () -> Unit, onSure: (String) -> Unit) {

    var inputText by remember { mutableStateOf("") }

    AlertDialog(
        shape = RoundedCornerShape(8.dp),
        onDismissRequest = onDismiss,
        title = {Text(stringResource(R.string.setting_6))},
        text = {
            SimpleTextEdit(
                value = inputText,
                onValueChange = { inputText = it },
                hint = stringResource(R.string.password),
                modifier = Modifier.fillMaxWidth()
            )
        },
        confirmButton = {
            Button(
                onClick = {
                    if(inputText.isNullOrBlank()){
                        UiHandler.showToast(R.string.enter_password_hint)
                    }else{
                        onSure(inputText)
                    }
                }
            ) {
                Text(stringResource(R.string.sure))
            }
        },
        dismissButton = {
            Button(
                onClick = {
                    onDismiss()

                }
            ) {
                Text(stringResource(R.string.cancel))
            }
        }
    )
}